pixelcache: use GtkStyleContext to determine cairo_content_t for surface
authorChristian Hergert <christian@hergert.me>
Tue, 8 Sep 2015 21:48:40 +0000 (14:48 -0700)
committerChristian Hergert <christian@hergert.me>
Sun, 13 Sep 2015 20:41:19 +0000 (13:41 -0700)
We can take a fast path if the background for a widget is opaque by using
a CAIRO_CONTENT_COLOR instead of a CAIRO_CONTENT_COLOR_ALPHA surface. Most
blit'ing backends have a fast path for this, including Pixman and Quartz.

https://bugzilla.gnome.org/show_bug.cgi?id=754658

gtk/gtkpixelcache.c
gtk/gtkpixelcacheprivate.h

index 2c0873e7a2ffe8e6a6e8d8ffd62d17ae100a5100..55d977e9d76256ffa3388a8aac03ab486474d5b0 100644 (file)
@@ -45,6 +45,9 @@ struct _GtkPixelCache {
   /* may be null if not dirty */
   cairo_region_t *surface_dirty;
 
+  /* background tracking for rgb/rgba */
+  GtkStyleContext *style_context;
+
   guint timeout_tag;
 
   guint extra_width;
@@ -88,6 +91,8 @@ _gtk_pixel_cache_free (GtkPixelCache *cache)
   if (cache->surface_dirty != NULL)
     cairo_region_destroy (cache->surface_dirty);
 
+  g_clear_object (&cache->style_context);
+
   g_free (cache);
 }
 
@@ -193,11 +198,8 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache         *cache,
   if (!content)
     {
       content = CAIRO_CONTENT_COLOR_ALPHA;
-      bg = gdk_window_get_background_pattern (window);
-      if (bg != NULL &&
-          cairo_pattern_get_type (bg) == CAIRO_PATTERN_TYPE_SOLID &&
-          cairo_pattern_get_rgba (bg, &red, &green, &blue, &alpha) == CAIRO_STATUS_SUCCESS &&
-          alpha == 1.0)
+      if (cache->style_context &&
+          _gtk_style_context_is_background_opaque (cache->style_context))
         content = CAIRO_CONTENT_COLOR;
     }
 
@@ -500,3 +502,11 @@ _gtk_pixel_cache_set_always_cache (GtkPixelCache *cache,
 {
   cache->always_cache = !!always_cache;
 }
+
+void
+_gtk_pixel_cache_set_style_context (GtkPixelCache   *cache,
+                                    GtkStyleContext *style_context)
+{
+  if (g_set_object (&cache->style_context, style_context))
+    _gtk_pixel_cache_invalidate (cache, NULL);
+}
index 8e1122c36fe98f7bbbcaf19bf9d247afbea3061f..264717aab80a5badcb51ecad7f667383f1d845ff 100644 (file)
@@ -54,6 +54,8 @@ void           _gtk_pixel_cache_set_content      (GtkPixelCache         *cache,
 gboolean       _gtk_pixel_cache_get_always_cache (GtkPixelCache         *cache);
 void           _gtk_pixel_cache_set_always_cache (GtkPixelCache         *cache,
                                                   gboolean               always_cache);
+void           _gtk_pixel_cache_set_style_context(GtkPixelCache         *cache,
+                                                  GtkStyleContext       *style_context);
 
 
 G_END_DECLS